package com.baykalcakici.cafepicker.listener;

import com.google.common.base.Preconditions;

import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.TextView;

public class PreviousMoveAnimationListener implements AnimationListener {
  private TextView currentView;
  private TextView previousView;
  private String text;

  public PreviousMoveAnimationListener(TextView currentView, TextView previousView, String text) {
    this.currentView = Preconditions.checkNotNull(currentView);
    this.previousView = Preconditions.checkNotNull(previousView);
    this.text = Preconditions.checkNotNull(text);
  }

  @Override
  public void onAnimationEnd(Animation animation) {
    currentView.setText(text);
  }

  @Override
  public void onAnimationRepeat(Animation animation) {
    // Nothing.
  }

  @Override
  public void onAnimationStart(Animation animation) {
    String prev = (currentView.getText() != null) ? currentView.getText().toString() : "";
    currentView.setText("");
    previousView.setText(prev);
  }
}
